package com.ricchieri.reports;

import java.util.ArrayList;
import java.util.Map;

import com.ricchieri.common.BusinessSettings;
import com.ricchieri.model.Reservation;
import com.ricchieri.util.FacesUtil;

public class ReservationReport extends ReportTemplate {
	private static final long serialVersionUID = 3745017294788565719L;
	private Reservation reservation;

	@Override
	protected void addParameters(Map<String, Object> parameters) {	
		parameters.put(BusinessSettings.REPORT_SCHEDULE_DATE, reservation.getScheduleCharter().getSchedule().getDate());
		parameters.put(BusinessSettings.REPORT_SCHEDULE_TIME, reservation.getScheduleCharter().getSchedule().getTime());
		parameters.put(BusinessSettings.REPORT_TRIP_ORIENTATION, reservation.getScheduleCharter().getTrip().getFormatTrip());
		parameters.put(BusinessSettings.REPORT_RESERVATION_NUMBER, reservation.getId());
		parameters.put(BusinessSettings.REPORT_FULLNAME, reservation.getUser().getFullName());
		
		parameters.put(BusinessSettings.REPORT_DNI, reservation.getUser().getDni());
		parameters.put(BusinessSettings.REPORT_DOCUMENT_TYPE, FacesUtil.getMessage(reservation.getUser().getDocumentType().getDescription()));
		parameters.put(BusinessSettings.REPORT_RESERVATION_TYPE, FacesUtil.getMessage(reservation.getReservationType().getDescription()));
		parameters.put(BusinessSettings.REPORT_UP_ON, reservation.getUpOn());
		parameters.put(BusinessSettings.REPORT_DOWN_ON, reservation.getDownOn());
		parameters.put(BusinessSettings.REPORT_TRIP_PRICE, reservation.getCost());
		parameters.put(BusinessSettings.REPORT_OPERATOR, reservation.getOperator().getFullName());
		parameters.put(BusinessSettings.REPORT_RESERVATION_COMMENTS, reservation.getObservation());
	}

	@Override
	public void generateReport(Map<String, Object> map,
			ReportFileFormat reportFileFormat) {
		 
		initReport(BusinessSettings.RESERVATION_REPORT, reportFileFormat);
		
		reservation = (Reservation) map.get(BusinessSettings.KEY_RESERVATION);
		
		try {
			
			String result = doWork(new ArrayList<Reservation>());
			
			if(!BusinessSettings.SUCCESS.equals(result)){
				FacesUtil.showInfoMessage("exportReport", "reportError");
			} else {
				FacesUtil.showInfoMessage("exportReport", "reportSuccess");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			FacesUtil.showInfoMessage("exportReport", "reportError");
		}

	}

}
